/* Geographically-Targeted Spending inMixed-Member Majoritarian Electoral Systems
Author: Amy Catalinac and Lucia Motolinia*/
*******Replication Code Tables*******

clear all
set more off
cd "D:\Users\Lucia\Dropbox\NYU\Papers\Catalinac & Motolinia\WP submission\_Replication_\"


*Table 2*
use "jap_data.dta", clear
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr  logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
reg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr dldp_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr dldp_vsharevp c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr dldp_vsharevp  logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr dldp_vsharevp c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
}

*Figure 1*
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
margins, at(invdldp_vsharevp_pr=(-10 (10) 10)) predict(xb) dydx(dkom_vsharevp_pr)
marginsplot, x(invdldp_vsharevp_pr) title("Average Marginal Effects of ΔKomeito PR VS with 95% CIs") xtitle("Negative ΔLDP PR VS") graphregion(col(white)) bgcol(white)

*Table 3*
*baseline
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
margins, dydx(dkom_vsharevp_pr) atmeans predict(xb)
*predicted effects
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
margins, at(invdldp_vsharevp_pr=(-10 (10) 10)) dydx(dkom_vsharevp_pr) predict(xb)

*Table 4*
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if komcands==1 & ldpcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/T4.tex",  keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr dldpkom_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
}

*Figure 2*
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if komcands==1 & ldpcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
margins, at(invdldp_vsharevp_pr=(-10 (10) 10)) predict(xb) dydx(dkom_vsharevp_pr)
marginsplot, x(invdldp_vsharevp_pr) graphregion(col(white)) bgcol(white) 

*Table 5*
*baseline
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if komcands==1 & ldpcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
margins, dydx(dkom_vsharevp_pr) atmeans predict(xb)
*predicted effects
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if komcands==1 & ldpcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
margins, at(invdldp_vsharevp_pr=(-10 (10) 10)) dydx(dkom_vsharevp_pr) predict(xb)

*Table 6*
use "mex_data.dta", clear
local varlist "lnfortalece10pc1"
foreach x in `varlist'{
reg `x' c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & candverde==1, robust cluster(district_year)  
outreg2 using "output/T6.tex", keep(c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B lnpopulation10  marg areakm2 density rural emergencia) dec(3) onecol se br symbol(***, **, *) replace
reg `x' c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & candverde==0, robust cluster(district_year)  
outreg2 using "output/T6.tex",  keep(c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B lnpopulation10  marg areakm2 density rural emergencia) dec(3) onecol se br symbol(***, **, *) append
reg `x' c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & coal==0, robust cluster(district_year)  
outreg2 using "output/T6.tex",  keep(c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B lnpopulation10  marg areakm2 density rural emergencia) dec(3) onecol se br symbol(***, **, *) append
}

*Figure 3*
reg lnfortalece10pc1 c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & candverde==1, robust cluster(district_year)  
margins, at(respri4B=(-10 (10) 10)) predict(xb) dydx(invresverdepri4B)
marginsplot, x(respri4B) graphregion(col(white)) bgcol(white) 

*Table 7*
*baseline
reg lnfortalece10pc1 c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & candverde==1, robust cluster(district_year)  
margins, atmeans predict(xb) dydx(invresverdepri4B)
*predicted effects
reg lnfortalece10pc1 c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & candverde==1, robust cluster(district_year)  
margins, at(respri4B=(-10 (10) 10)) predict(xb) dydx(invresverdepri4B)

*Appendix D*
use "jap_data.dta", clear
local varlist "komcands dkom_vsharevp_pr invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density"
foreach x in `varlist'{
display "`x'"
sum `x' if   year==2000 | year==2003 | year==2005 | year==2012
return list
sca m1=r(mean)
sca m2=r(sd)
sca m3=r(min)
sca m4=r(max)
sca m5=r(N)
matrix col1 =nullmat(col1) \ (m1)  
matrix col2 =nullmat(col2) \ (m2) 
matrix col3 =nullmat(col3) \ (m3) 
matrix col4 =nullmat(col4) \ (m4) 
matrix col5 =nullmat(col5) \ (m5) 
}
mat appA= col1,col2,col3,col4,col5
matlist appA
outtable using "output/descstat_japan.tex", mat(appA) replace center f(%9.3f %9.3f %9.3f %9.3f)

use "mex_data.dta", clear
local varlist "lnfortalece10pc1 invresverdepri4B respri4B lnpopulation10  marg areakm2 density rural emergencia" 
foreach x in `varlist'{
display "`x'"
sum `x' if  year==2012 | year==2015
return list
sca m1=r(mean)
sca m2=r(sd)
sca m3=r(min)
sca m4=r(max)
sca m5=r(N)
matrix col1 =nullmat(col1) \ (m1)  
matrix col2 =nullmat(col2) \ (m2) 
matrix col3 =nullmat(col3) \ (m3) 
matrix col4 =nullmat(col4) \ (m4) 
matrix col5 =nullmat(col5) \ (m5) 
}
mat appA= col1,col2,col3,col4,col5
matlist appA
outtable using "output/descstat_mex.tex", mat(appA) replace center f(%9.3f %9.3f %9.3f %9.3f)
 
*Appendix E*
use "jap_data.dta", clear
*Table E.1
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr  logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
reg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr dldp_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr dldp_vsharevp c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr dldp_vsharevp  logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/T2.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr dldp_vsharevp c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
}
*Figure E.1
keep if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012)
egen Xbin= cut(dkom_vsharevp_pr), group(3)
interflex newf1logngaid_pc invdldp_vsharevp_pr dkom_vsharevp_pr dldp_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density, vce(r)

*Table E.2
use "jap_data.dta", clear
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr  mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/nickel.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr dldp_vsharevp mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/nickel.tex", keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr dldp_vsharevp c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
}

*Appendix F*
*Table F.1
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if komcands==1 & ldpcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/T4.tex",  keep(c.dkom_vsharevp_pr#c.invdldp_vsharevp_pr c.dkom_vsharevp_pr c.invdldp_vsharevp_pr dldpkom_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
}
*Figure F.1
keep if ldpcands==0 & komcands==1 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012)
egen Xbin= cut(dkom_vsharevp_pr), group(3)
interflex newf1logngaid_pc invdldp_vsharevp_pr dkom_vsharevp_pr  logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density, vce(r)

*Appendix G*
use "placebo.dta", clear
*Table G.1
local varlist "nonldpkom"
foreach x in `varlist'{
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr c.invd`x'_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/placebo.tex", keep(c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr c.invd`x'_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
xtreg newf1logngaid_pc c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr c.invd`x'_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/placebo.tex", keep(c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr c.invd`x'_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
reg newf1logngaid_pc c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr c.invd`x'_vsharevp_pr dldp_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012), robust cluster(hor_electoral_district) 
outreg2 using "output/placebo.tex", keep(c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr dldp_vsharevp c.invd`x'_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
xtreg newf1logngaid_pc c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr c.invd`x'_vsharevp_pr dldp_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.yeardistrict if ldpcands>0 & komcands==0 & split_mun_jed==0 & (year==2003 | year==2005 | year==2012),fe robust cluster(hor_electoral_district) nonest
outreg2 using "output/placebo.tex", keep(c.dkom_vsharevp_pr#c.invd`x'_vsharevp_pr c.dkom_vsharevp_pr dldp_vsharevp c.invd`x'_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
}

*Appendix I*
use "mex_data.dta", clear
*Table I.1
local varlist "lnfortalece10pc1"
foreach x in `varlist'{
reg `x' c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & candverde==1, robust cluster(district_year)  
outreg2 using "output/T6.tex", keep(c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B lnpopulation10  marg areakm2 density rural emergencia) dec(3) onecol se br symbol(***, **, *) replace
reg `x' c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & candverde==0, robust cluster(district_year)  
outreg2 using "output/T6.tex",  keep(c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B lnpopulation10  marg areakm2 density rural emergencia) dec(3) onecol se br symbol(***, **, *) append
reg `x' c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B  lnpopulation10  marg areakm2 density rural emergencia i.district_year if split!=1 & coal==0, robust cluster(district_year)  
outreg2 using "output/T6.tex",  keep(c.invresverdepri4B#c.respri4B  c.invresverdepri4B c.respri4B lnpopulation10  marg areakm2 density rural emergencia) dec(3) onecol se br symbol(***, **, *) append
}

*Figure I.1
keep if split!=1 & candverde==1
rename marg poverty
egen Xbin= cut(respri4B), group(3)
interflex lnfortalece10pc1 invresverdepri4B respri4B  lnpopulation10  poverty areakm2 density rural emergencia, vce(r)

